home *** CD-ROM | disk | FTP | other *** search
- Path: felix.teclink.net!usenet
- From: rad@teclink.net (rad)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: Must I free my linked lists? (GCC)
- Date: 26 Jan 1996 02:45:25 GMT
- Organization: TECLink Internet Services: info@TECLink.Net
- Message-ID: <1875.6597T1319T164@teclink.net>
- References: <4dvn6t$lc3@hamilton.maths.tcd.ie>
- NNTP-Posting-Host: tc1_13.teclink.net
- X-Newsreader: THOR 2.22 (Amiga;TCP/IP) *UNREGISTERED*
-
-
- >rid@red-branch.MIT.EDU (Shawna Grimm) writes:
-
- >>Unknown (Dannyman@uiuc.edu) typed in the following on 21 Jan 1996 22:09:16
- >>GMT:
- >>: I'm writing a program that makes use of dynamic memory allocation
- >>: through
- >>: linked lists using malloc() ... from an implementation PoV there's no need
- >>: to flush this stuff as after the queue is created it's output and the
- >>: program exits. My question is;
-
- >>Yes, you _should_ free any memory that you allocate in your program.
- >>Memory that is allocated and not freed will not be returned to the system
- >>unless you turn the machine off, so if you want your memory back, you
- >>must free it. Personally, I would prefer to use AllocMem() or AllocVec()
- >>(with FreeMem() and FreeVec() ofcourse).
-
- >I think the memory is freed in when you use malloc - in gcc or SAS/C.
- >Weither this is in malloc's spec is another matter. I think
- >memory you malloc ( as opposed to AllocMem'ed ) seems to be tracked
- >and freed at exit. I noticed this when I was testing something I was
- >writing on unix, and hadn't finished the memory stuff. It allocates
- >about 8MB, which went fine, but I was quite shoked to see that I could
- >run it twice in a row ( I only have 10MB of ram ).
-
- Yes, ANSI-C compilers will track all memory allocated by malloc() calloc() and
- realloc() and free them on exiting the program. It of course is better to
- free your own memory as you finish with so that if you start looping your code
- in the future you don't require gigabytes to run it.
-
- --------------------------------------------------------------------------
- - Richard Deken E-Mail: (personal) rad@teclink.net -
- - VLSI design engineer (AuE business) rad@aue.com -
- - Advanced Microelectronics PGP public key available -
- --------------------------------------------------------------------------
-
-